package 力扣._17电话号码的字母组合;

import java.util.LinkedList;
import java.util.List;

class Solution {

    void backtrack(char[][] yinshe, int[] nums, int now, StringBuilder s, List<String> list) {
        if (now == nums.length) {
            list.add(s.toString());
        }
        int len = 3;
        if (nums[now] == 7)
            len = 4;
        for (int i = 0; i < len; i++) {
            s.append(yinshe[nums[now]][i]);
            backtrack(yinshe, nums, now + 1, s, list);
            s.deleteCharAt(s.length() - 1);
        }
    }

    public List<String> letterCombinations(String digits) {
        char[][] yinshe = new char[][]{
                {'a', 'b', 'c'},    //0
                {'a', 'b', 'c'},    //1
                {'a', 'b', 'c'},    //2
                {'d', 'e', 'f'},
                {'g', 'h', 'i'},
                {'j', 'k', 'l'},
                {'m', 'n', 'o'},
                {'p', 'q', 'r', 's'},
                {'t', 'u', 'v'},
        };
        StringBuilder s = new StringBuilder();
        List<String> list = new LinkedList<>();
        int[] nums = new int[digits.length()];
        for (int i = 0; i < digits.length(); i++) {
            nums[i] = digits.charAt(i) - '0';
        }
        backtrack(yinshe, nums, 0, s, list);
        return list;
    }
}